package com.baizhi.zyj.controller;

import com.baizhi.zyj.entity.Admin;
import com.baizhi.zyj.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.Map;

@Controller
@CrossOrigin
@RequestMapping("admin")
public class AdminController{
    @Autowired
    private AdminService adminService;

    @ResponseBody
    @RequestMapping("getImageCodes")
    Map<String,String> getImageCodes() throws IOException {
        return adminService.getImageCodes();
    }

    //登录
    @ResponseBody
    @RequestMapping("login")
//    @RequestMapping(value = "login",method = RequestMethod.POST)
//    @CrossOrigin(origins = "*",maxAge = 3600)
    Map<String,String> login(@RequestBody Admin admin,String token){
        return adminService.login(admin,token);
    }


    //获取登录用户信息
    @ResponseBody
    @RequestMapping("getUserInfo")
    Admin getUserInfo(String token){
        return adminService.getUserInfo(token);
    }
    //退出
    @ResponseBody
    @RequestMapping("logout")
    void logout(String token){
        adminService.logout(token);
    }
}
